package com.chengda.dashboard.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chengda.dashboard.entity.AlarmInfo;
import com.chengda.dashboard.mapper.AlarmInfoMapper;
import com.chengda.dashboard.service.AlarmInfoService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 报警信息服务实现类
 */
@Service
public class AlarmInfoServiceImpl extends ServiceImpl<AlarmInfoMapper, AlarmInfo> implements AlarmInfoService {

    @Override
    public List<AlarmInfo> getAllUnprocessedAlarms() {
        QueryWrapper<AlarmInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 0);
        queryWrapper.orderByDesc("alarm_level").orderByDesc("create_time");
        return list(queryWrapper);
    }

    @Override
    public List<AlarmInfo> getAlarmsByMachineNo(String machineNo) {
        QueryWrapper<AlarmInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("machine_no", machineNo);
        queryWrapper.eq("status", 0);
        queryWrapper.orderByDesc("create_time");
        return list(queryWrapper);
    }

    @Override
    public List<AlarmInfo> getAllAlarmInfo() {
        QueryWrapper<AlarmInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("alarm_level").orderByDesc("create_time");
        return list(queryWrapper);
    }
}
